package fun.formoji.alg.api.fallback;


import feign.hystrix.FallbackFactory;
import fun.formoji.alg.api.OfflineAlgApi;
import fun.formoji.alg.resp.CouponScoreResultVo;
import fun.formoji.alg.resp.GbdtAlgResultVo;
import fun.formoji.alg.resp.LfmAlgResultVo;
import fun.formoji.alg.resp.ShoppingBasketResultVo;
import fun.formoji.commons.model.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author h
 * @date 2020/12/29 13:36
 * @description
 */
@Component
@Slf4j
public class OfflineAlgApiFallBackFactory implements FallbackFactory<OfflineAlgApi> {
    @Override
    public OfflineAlgApi create(Throwable cause) {
        log.error("Failed to call {},reason:{}", OfflineAlgApi.class.getName(),cause.getMessage(), cause);
        return new OfflineAlgApi() {
            @Override
            public RestResponse<LfmAlgResultVo> lfm(String userId) {
                return RestResponse.fallback();
            }

            @Override
            public RestResponse<GbdtAlgResultVo> gbdt(String userId) {
                return RestResponse.fallback();
            }

            @Override
            public RestResponse<CouponScoreResultVo> couponScore(String userId) {
                return RestResponse.fallback();
            }

            @Override
            public RestResponse<ShoppingBasketResultVo> shoppingBasket(List<String> itemIds) {
                return RestResponse.fallback();
            }
        };
    }
}
